-
Notifications
You must be signed in to change notification settings - Fork 342
rpc: Implement possibility to stop and resume all the RPC communication #1886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
nrf_rpc/include/nrf_rpc.h
Outdated
| void nrf_rpc_register_cleanup_handler(struct nrf_rpc_cleanup_handler * handler); | ||
|
|
||
|
|
||
| /** @brief Temporairly suspend all RPC communication |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /** @brief Temporairly suspend all RPC communication | |
| /** @brief Temporarily suspend all RPC communication |
nrf_rpc/include/nrf_rpc.h
Outdated
| /** @brief Temporairly suspend all RPC communication | ||
| * | ||
| * Calling this function automatically fails all communication until @ref nrf_rpc_resume is called. | ||
| * It also causes all pending request to fail immediately. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * It also causes all pending request to fail immediately. | |
| * It also causes all pending commands to fail immediately. |
nrf_rpc/include/nrf_rpc.h
Outdated
| * | ||
| * @param cleanup set to true to also invoke all the custom cleanup handlers. | ||
| * | ||
| * @note If the cleanup parameter is set to true it may be needed to reset the RPC server before invoking |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * @note If the cleanup parameter is set to true it may be needed to reset the RPC server before invoking | |
| * @note If the cleanup parameter is set to true it may be needed to reset the peer before invoking |
nRF RPC has no concept of client/server.
I think this note may be a bit confusing as to why the peer must be reset though. Also the local device may not be capable of resetting the peer. This note might require some explanation for this reason.
nrf_rpc/nrf_rpc.c
Outdated
| #include <stdbool.h> | ||
| #include <string.h> | ||
|
|
||
| #include <zephyr/kernel.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No Zephyr includes please.
nrf_rpc/nrf_rpc.c
Outdated
| for (int i = 0; i < CONFIG_NRF_RPC_CMD_CTX_POOL_SIZE; i++) { | ||
| struct nrf_rpc_cmd_ctx *ctx = &cmd_ctx_pool[i]; | ||
| nrf_rpc_os_mutex_lock(&ctx->mutex); | ||
| if (ctx->recv_msg.waiting > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to have changed the nrf_rpc_os_msg - requiring that it support waiting member. If so then nrf_rpc_os_tmpl.h needs to be udpated and release notes added. I wonder if we couldn't rely on ctx->use_count, instead. The only possibility that use_count > 0 and ctx->mutex is unlocked is because the context owners is waiting for a response.
nrf_rpc/nrf_rpc.c
Outdated
| hdr.type == NRF_RPC_PACKET_TYPE_EVT || | ||
| hdr.type == NRF_RPC_PACKET_TYPE_RSP)) { | ||
| // drop only selected types of packets | ||
| // do not drop ACKs INITs and ERRORS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for excluding ACKs as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking it is best to allow acks to consider frame delivered and possibly prevent re-transmissions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, but these are not transport-level ACKs. nRF RPC has ACK packets (not frames) to acknowledge event reception :).
nrf_rpc/nrf_rpc.c
Outdated
| hdr.dst_group_id = group->data->dst_group_id; | ||
| header_cmd_encode(full_packet, &hdr); | ||
| cmd_ctx = cmd_ctx_reserve(); | ||
| nrf_rpc_os_mutex_unlock(&cleanup_mutex); /* release the mutex as the context specific one has been aqqured */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| nrf_rpc_os_mutex_unlock(&cleanup_mutex); /* release the mutex as the context specific one has been aqqured */ | |
| nrf_rpc_os_mutex_unlock(&cleanup_mutex); /* release the mutex as the context specific one has been acquired */ |
e44343f to
547dc8a
Compare
547dc8a to
7b4557b
Compare
nrf_rpc/nrf_rpc.c
Outdated
|
|
||
| static void abort_all_ops(void) | ||
| { | ||
| NRF_RPC_WRN("Canceling all tasks."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be a warn? It seems to be expected after user's action, how about using info level?
nrf_rpc/include/nrf_rpc.h
Outdated
| * after the function has finished. | ||
| * | ||
| */ | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accidental newline
nrf_rpc/include/nrf_rpc.h
Outdated
| void (*handler)(void *context); | ||
|
|
||
| /** @brief Custom context passed as the function parameter */ | ||
| void *context; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double space. It seems that compliance script is not running for this repository.
nrf_rpc/nrf_rpc.c
Outdated
| return err; | ||
| } | ||
|
|
||
| void nrf_rpc_register_cleanup_handler(struct nrf_rpc_cleanup_handler * handler) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| void nrf_rpc_register_cleanup_handler(struct nrf_rpc_cleanup_handler * handler) | |
| void nrf_rpc_register_cleanup_handler(struct nrf_rpc_cleanup_handler *handler) |
nrf_rpc/nrf_rpc.c
Outdated
| { | ||
| nrf_rpc_os_mutex_lock(&cleanup_mutex); | ||
|
|
||
| struct nrf_rpc_cleanup_handler * current; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| struct nrf_rpc_cleanup_handler * current; | |
| struct nrf_rpc_cleanup_handler *current; |
nrf_rpc/nrf_rpc.c
Outdated
| is_stopped = true; | ||
| abort_all_ops(); | ||
| if (cleanup) { | ||
| struct nrf_rpc_cleanup_handler * current; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| struct nrf_rpc_cleanup_handler * current; | |
| struct nrf_rpc_cleanup_handler *current; |
| current->handler(current->context); | ||
| } | ||
| } | ||
| nrf_rpc_os_mutex_unlock(&cleanup_mutex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe newline?
nrf_rpc/include/nrf_rpc.h
Outdated
| * | ||
| */ | ||
|
|
||
| void nrf_rpc_register_cleanup_handler(struct nrf_rpc_cleanup_handler * handler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| void nrf_rpc_register_cleanup_handler(struct nrf_rpc_cleanup_handler * handler); | |
| void nrf_rpc_register_cleanup_handler(struct nrf_rpc_cleanup_handler *handler); |
7b4557b to
a8c72d6
Compare
Implemented stop function that immedtaietly releases all threads waiting for RPC response and automatically fails all new calls. Implemented resume function that restores normal RPC communication. This is intended to be used for recovery process when the other side needs to be reset but there are calls waiting for the response. Additionally it is possible to provide callback handler that could be used to do the custom cleanup, for example clear the callback table. Signed-off-by: Marek Porwisz <[email protected]>
a8c72d6 to
29c502d
Compare
|



Implemented stop function that immedtaietly releases all threads waiting for RPC response and automatically fails all new calls. Implemented resume function that restores normal RPC communication. This is intended to be used for recovery process when the other side needs to be reset but there are calls waiting for the response. Additionally it is possible to provide callback handler that could be used to do the custom cleanup, for example clear the callback table.